<template>
	<view class="address_box" style="background: #F9F9F9;">
		<view class="" style="height: 66vh; overflow-y: auto ;">
			<view class="address_box_item flex_sb flxe_al" v-for="(item,index) in list_add	" :key='index'>
				<view class="address_box_item_text flxe_al" @click="set_add(item.id)">
					<view class="address_box_item_text_xuan" :class="item.is_default==1?'address_box_item_text_xuan_active':''">
						<u-icon v-show='item.is_default==1' class="i_icon" name="checkbox-mark" color="#FF9A33" size="18"></u-icon>
					</view>
					<view class="widths">
						<view class="address_box_item_text_title">
							{{item.contacts}} {{item.contacts_mobile}}
						</view>
						<view class="address_box_item_text_deitle">
							{{item.area}}{{item.address}}
						</view>
					</view>
				</view>
				<view class="address_box_item_image" @click="pageTo(1,item.id)">
					<img src="https://z1.ax1x.com/2023/09/15/pPWtlM8.png" alt="">
				</view>
			</view>
		</view>
		
		<view class="bottons" @click="pageTo(0)">
			添加地址
		</view>
		<u-toast ref="uToast" />
		
	</view>
</template>

<script>
	export default {

		data() {
			return {
				list_add:[],//地址数组
				ids: 0, //设置默认地址id
			}
		},
		onLoad() {
		
		},
		onShow() {
			this.getadd()
		},
		methods: {
			pageTo(type, ids) {
				uni.navigateTo({
					url: "/pages/my/add_address?type=" + type + '&id=' + ids
				})
			},
			// 获取地址
			getadd() {
				uni.$u.http.post('user/address_list', {
					openid: uni.getStorageSync('openid'),
					user_id: uni.getStorageSync('userId')
				}).then(res => {
					this.list_add = res.data
				})
			},
			// 点击修改默认地址
			set_add(ids){
				var sq = {}
				// 获取地址信息
				uni.$u.http.post('user/address_edit_list', {
					openid: uni.getStorageSync('openid'),
					user_id: uni.getStorageSync('userId'),
					id:ids
				}).then(res => {
					res.data.is_default=1
					sq=res.data
					sq['openid']=uni.getStorageSync('openid')
					sq['user_id']=uni.getStorageSync('userId')
					this.disfl(sq)
				})
			},
			// 设置默认地址
			disfl(sqs) {
				let _this=this
				uni.$u.http.post('user/address_edit_save',sqs).then(res => {
					if(res.code==200){
						_this.$refs.uToast.show({
							title: '默认地址设置成功',
						})
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							});
						}, 500)
					}
					
					_this.getadd()
				})
			}
		}
	}
</script>


<style lang="less" scoped>
	.widths{
		 width:calc(100% - 34rpx - 40rpx)
	}
	.address_box {
		padding: 20rpx;
	}

	.address_box_item {
		padding: 30rpx 20rpx;
		background: #ffffff;
		margin-bottom: 20rpx;
	}

	.address_box_item_image>image {
		width: 34rpx;
		height: 34rpx;
	}

	.address_box_item_text_xuan {
		width: 31rpx;
		height: 31rpx;
		border: 2rpx solid #C6C4C4;
		border-radius: 50%;
		margin-right: 18rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.address_box_item_text_title {
		font-size: 30rpx;
		font-weight: 550;
		color: #333333;
		margin-bottom: 16rpx;
	}

	.address_box_item_text_deitle {
		font-size: 24rpx;
		font-weight: 400;
		color: #666666;
	}

	.address_box_item_text_xuan_active {
		border: 2rpx solid #FF9A33;
	}

	.bottons {
		width: 500rpx;
		height: 80rpx;
		background: #FF9A33;
		border-radius: 40rpx;
		text-align: center;
		line-height: 80rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #FFFFFF;
		margin: 200rpx auto 0;
	}
</style>